/*
* @Author: Flora
* @Date:   2019-01-14 20:25:46
* @Last Modified by:   Flora
* @Last Modified time: 2019-01-18 20:39:17
*/
'use strict';
require('./index.css');
require('page/common/footer/index.css');
require('page/common/nav/index.js');
require('util/jq-shake.js');
var _mm = require('util/mm.js');
var md5 = require("md5");
var _user = require('service/user-service.js');

var page={
	init:function(){
		this.bindEvent();
	},
	bindEvent:function(){
		var _this = this;
		$('#username').click(function(){
			$('#username').css('border-color','#bdbdbd');
		});
		$('#password').click(function(){
			$('#password').css('border-color','#bdbdbd');
		});
		$('#login-submit').click(function(){
			_this.submit();
		});
		// TODO 按回车提交
	},
	submit:function(){
		var _this = this;
		var formData = {
			username : $.trim($('#username').val()),
			password : md5($.trim($('#password').val())) /*MD5加密*/
		};
		if(formData.username == ""){
			// 用户名为空
			// alert('null');
			$('#username').css('border-color','red');
			$('#username').shake(10,5,400);
			return ;
		}
		if(md5('') === formData.password){
			// 密码为空
			$('#password').css('border-color','red');
			$('#password').shake(10,5,400);
			return ;
		}
		// 验证成功
		console.log('开始登录');
		_user.login(formData,function(resData){
			window.location.href= _mm.getUrlParam('redirect') || './index.html';
		}, function(errMsg){
			alert('用户名或密码错误'+errMsg);
		});
	}
};
$(function(){
	page.init();
});

// buyer ---reyub---37254660e226ea65ce6f1efd54233424
//seller --relles---981c57a5cfb0f868e064904b8745766f

// http://localhost:8866/dist/view/user-login.html?redirect=http%3A%2F%2Flocalhost%3A8866%2Fdist%2Fview%2Fuser-login.html%3F
// redirect%3Dhttp%253A%252F%252Flocalhost%253A8866%252Fdist%252Fview%252Fuser-login.html%253F
// redirect%253Dhttp%25253A%25252F%25252Flocalhost%25253A8866%25252Fdist%25252Fview%25252Fuser-login.html%25253F
// redirect%25253Dhttp%2525253A%2525252F%2525252Flocalhost%2525253A8866%2525252Fdist%2525252Fview%2525252Fuser-login.html
// http://localhost:8866/dist/view/user-login.html